package main

import (
	"ServerDemo/tcp_client"
	TcpServer "ServerDemo/tcp_server"
	"flag"
	"fmt"
	"github.com/panjf2000/gnet"
	"log"
)

func main() {

	var port int
	var multicore bool

	// Example command: go run main.go --port 5000 --multicore true
	flag.IntVar(&port, "port", 5000, "server port")
	flag.BoolVar(&multicore, "multicore", true, "multicore")
	flag.Parse()
	tcpServer := TcpServer.NewTCPServer(port)

	//启动client
	go func() {
		for i := 0; i < 1; i++ {
			go func() {
				tcp_client.TcpClient(port)
			}()
		}
	}()

	//启动server
	log.Fatal(gnet.Serve(tcpServer, fmt.Sprintf("tcp://:%d", port), gnet.WithMulticore(multicore)))
}
